<?php

class JsonizerHelper {
    public $jsonObjects;
    public $phpObjects;
    
    private $counter;
    
    function __construct() {
        $this->jsonObjects = array();
        $this->phpObjects = array();
        
        $this->counter = 0;
    }
    
    /* **************************************** */
    
    function fetchRef($phpObject) {
        $toReturn = null;
        foreach ($this->phpObjects as $ref => $object) {
            if ($object === $phpObject) {
                $toReturn = $ref;
                break;
            }
        }
        
        return $toReturn;
    }
    
    function createRef($phpObject) {
        $ref = "a" . dechex($this->counter++);
        $this->phpObjects[$ref] = $phpObject;
        return $ref;
    }
    
    function putJson($ref, $jsonObject) {
        $this->jsonObjects[$ref] = $jsonObject;
    }
    
    /* **************************************** */
    
    function getObject($ref) {
        if (array_key_exists($ref, $this->phpObjects)) {
            return $this->phpObjects[$ref];
        } else {
            return null;
        }
    }
    
    function putObject($ref, $phpObject) {
        $this->phpObjects[$ref] = $phpObject;
    }
    
    function getJson($ref) {
        return $this->jsonObjects[$ref];
    }
}

?>
